package com.shrcl.engineerprocess.domain;

import com.shrcl.engineerprocess.domain.Engineer;
import com.shrcl.engineerprocess.domain.EngineerLevel;
import com.shrcl.engineerprocess.domain.EngineerLevelSalary;
import com.shrcl.engineerprocess.domain.EngineerLevelSalaryDAO;
import com.shrcl.engineerprocess.domain.EngineerMonthlyCost;
import com.shrcl.engineerprocess.domain.events.EngineerMonthlyCostEventsListener;
import edu.fudan.mylang.pf.event.BaseEntityEventsListener;
import java.util.Collection;
import java.util.Date;
import org.eclipse.xtext.xbase.lib.IterableExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("com.shrcl.engineerprocess.domain.EngineerSalaryListener")
public class EngineerSalaryListener extends BaseEntityEventsListener<EngineerMonthlyCost> implements EngineerMonthlyCostEventsListener {
  @Autowired
  private EngineerLevelSalaryDAO engineerLevelSalaryDAO;
  
  public void entityCreated(final EngineerMonthlyCost entity) {
  }
  
  public void updateCost(final EngineerMonthlyCost entity, final Procedure1<? super EngineerMonthlyCost> updater) {
  }
  
  public void EngineerMonthlyCostUpdate(final EngineerMonthlyCost entity) {
    Engineer _engineer = entity.getEngineer();
    Collection<EngineerLevel> _newestMonthlyCostLevels = _engineer.getNewestMonthlyCostLevels();
    final Procedure1<EngineerLevel> _function = new Procedure1<EngineerLevel>() {
        public void apply(final EngineerLevel it) {
          EngineerLevelSalary _engineerLevelSalaryByLevel = EngineerSalaryListener.this.engineerLevelSalaryDAO.getEngineerLevelSalaryByLevel(it);
          Date _month = entity.getMonth();
          _engineerLevelSalaryByLevel.updateCost(_month);
        }
      };
    if (_newestMonthlyCostLevels!=null) IterableExtensions.<EngineerLevel>forEach(_newestMonthlyCostLevels, _function);
  }
}
